import * as React from "react";
import { connect } from "react-redux";
import { Redirect, Route, RouteComponentProps } from "react-router";

class AuthRoute extends React.Component<any> {

    public render() {
        const { component: Component, ...rest } = this.props;
        return (
            <Route
                {...rest}
                render={(props: RouteComponentProps<any>) =>
                    window.localStorage.getItem("phone") ? <Component {...props} /> : <Redirect to={"/login"} />
                }
            />
        );
    }
}
const mapStateToProps = (state: any) => {
    return {
        user: state
            .get("loginOrLogoutReducer")
            .get("user")
            .toJS()
    };
};

export default connect(mapStateToProps)(AuthRoute);

